function d = frac2cur(p, f)
%FRAC2CUR Fractional currency values to decimal values.
%
%   D = frac2cur(P, F)
%
%   Inputs:
%   P - String or cell array of the fractional currency value.
%
%   F - Scalar or vector of the denominators.
%
%   Outputs:
%   D - Scalar or vector of the fractional currency values.
%
%   Example:
%      d = frac2cur('12.1', 8)
%      d = 12.125
%
%   See also CUR2FRAC, CUR2STR.
 
%       Copyright 1995-2006 The MathWorks, Inc.
%       $Revision: 1.9.2.3 $   $Date: 2006/06/16 20:09:43 $ 
 
if nargin < 2 
  error('finance:frac2cur:missingInputs','Missing one of P and F.') 
end 
 
if nargin < 2
    error('Finance:frac2cur:tooFewInputs', 'Too few inputs.')
end

if isempty(p) || isempty(f)
    d = [];
    return
end

% Input validation
if ischar(p)
    p = cellstr(p);
end

[rp, cp] = size(p); %#ok

if numel(f) == 1
    % Scalar expansion
    f = f * ones(rp, cp);
end

[rf, cf] = size(f); %#ok

if numel(p) == 1
    % Scalar expansion
    p = repmat(p, rf, cf);
end

[ecode1, errMsg1] = checksiz([[rp, cp]; [rf, cf]], mfilename);
if ecode1
    error('Finance:frac2cur:conflictingDataSizes', errMsg1)
end

% Algorithm
d = zeros(size(p));
for i = 1:numel(d)
    % Check for '-' signs
    if p{i}(1) == '-'
        coeff = -1;
        p{i}(1) = [];

    else
        coeff = 1;
    end

    % Find the decimal point
    b = find(p{i} == '.');

    if isempty(b)
        d(i) = str2double(p{i});

    else
        temp = p{i};
        [m, n] = size(temp);  %#ok
        d(i) = coeff*(str2double(temp(1, 1:b-1)) + str2double(temp(1, b+1:n))/f(i));
    end
end


% [EOF]
